package com.geek.bams.dao;

import com.geek.bams.entity.Account;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc 基于集合操作的CRUD
 * @Author wangpeng
 * @Date 2025/10/13
 */
public class ListDao implements IDao<Account , List<Account>>{

    //集合容器
    List<Account> accs = new ArrayList<>();
    //初始ID
    private Long id = 100000000000000000L;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

  /*  @Override
    public boolean insert(Account account) {
        return false;
    }

    @Override
    public Account selectOne(Long id, String password) {
        return null;
    }

    @Override
    public Account selectOne(Long id) {
        return null;
    }

    @Override
    public List<Account> selectAll() {
        return Collections.emptyList();
    }*/
  //插入账户
  public boolean insert(Account acc){
     accs.add(acc);
      return true;
  }

    //根据ID和密码查询账户
    public Account selectOne(Long id , String password){
        for(Account acc : accs){
            //id.equals(acc.getId())  这种写法，因为在业务方法对id,password进行判空过，只有非空，才能进来，避免空指针
            if(acc.getId().equals(id) && acc.getPassword().equals(password)){
                return acc;
            }
        }
        return null;
    }

    //根据ID查询账户
    public Account selectOne(Long id){
        for(Account acc : accs){
            if(acc.getId().equals(id)){
                return acc;
            }
        }
        return null;
    }

    //查询所有账户
    public List<Account> selectAll(){
        return accs;
    }
}
